package com.fa4j.common.base.convert;


import com.fa4j.common.base.model.AbstractCmd;
import com.fa4j.common.base.model.ModifyCmd;
import org.mapstruct.BeanMapping;
import org.mapstruct.MapperConfig;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.control.DeepClone;

@MapperConfig(uses = ConverterConfig.class)
public interface CommonConvertor<ENTITY, CREATE_CMD extends AbstractCmd, MODIFY_CMD extends ModifyCmd<?>> {

    ENTITY toEntity(CREATE_CMD cmd);

    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
    void updateEntity(@MappingTarget ENTITY entity, MODIFY_CMD cmd);

    @BeanMapping(mappingControl = DeepClone.class)
    ENTITY clone(ENTITY entity);

}
